<template>
  <div>
    <el-container>
      <el-main>
        <kendoForm
          :kendo-form-items="kendoFormItems"
          :kendo-form="kendoForm"
          :kendo-params-value="kendoParamsValue"
        />
      </el-main>
    </el-container>
    <el-container style="padding-left:5px">
      <el-main>
        <KendoGridCmpt
          ref="UserGrid"
          :table-grid-option="tableGridOption"
          :table-grid-data-source-option="tableGridDataSourceOption"
          :table-grid-toolbar="tableGridToolbar"
          @persistSelection="selectDataItems"
        />
      </el-main>
    </el-container>
  </div>

</template>

<script>
  import kendoForm from '@/Views/components/kendo-vue-component/kendoForm/index.vue'
  export default {
    name: 'UserManage',
    components: {
      kendoForm
    },
    data() {
      return {
        /* Form*/
        kendoFormItems: [
          {
            name: 'userId',
            label: '用户编号',
            paramName: 'userId',
            controlType: 'input'
          },
          {
            name: 'userName',
            label: '用户名称',
            paramName: 'userName',
            controlType: 'input'
          }
        ],
        kendoForm: {
          ref: 'UserSearchForm',
          valid: 'valid',
          buttons: [
            {
              name: '查询', // 按钮内容
              class: 'k-primary', // 按钮样式
              icon: 'search',
              click: this.search
            },
            {
              name: '重置', // 按钮内容
              icon: 'reset-sm', // 按钮样式
              click: this.reset
            }
          ]
        },
        kendoParamsValue: {
          userId: '',
          userName: ''
        },
        /* Grid*/
        tableGridToolbar: [
          {
            text: '用户新增',
            class: 'k-primary',
            icon: 'dictionary-add',
            option: {
              /** @Description
                 模式 ：dataReq:数据操作，请求后台处理 dataView 数据操作，请求前端页面渲染视图
                 model: 'dataReq',
                 如果是dataReq 那么必须要有 :{
                  transportRequestUrl: ''(请求地址)
                  parameterMap (请求参数)
                 }
              */
              model: 'dataView',
              componentUrl: '/sysmanage/usermanage/operate/index.vue',
              dialogTitle: '用户新增',
              parameterMap: {}
            },
            /**
             * @description 操作类型 add (新增) update(修改) del(删除) view(查看)
            */
            operatorType: 'add'
          },
          {
            text: '修改',
            class: 'k-primary',
            icon: 'edit',
            option: {
              /** @Description
                 模式 ：dataReq:数据操作，请求后台处理 dataView 数据操作，请求前端页面渲染视图
                 model: 'dataReq',
                 如果是dataReq 那么必须要有 :{
                  transportRequestUrl: ''(请求地址)
                  parameterMap (请求参数)
                 }
              */
              model: 'dataView',
              componentUrl: '/sysmanage/usermanage/operate/index.vue',
              dialogTitle: '修改字典参数',
              parameterMap: {}
            },
            /**
             * @description 操作类型 add (新增) edit(修改) del(删除) view(查看)
            */
            operatorType: 'edit'
          }
        ],
        // maintain 字典数据列表
        tableGridOption: {
          ref: 'userOptGrid',
          dataSourceRef: 'dictDataSource',
          remoteData: true,
          sortable: true,
          reorderable: true,
          resizable: true,
          pageable: true,
          selectSingle: true,
          selectMultiple: false,
          toolbar: ['excel'],
          excel: {
            fileName: '用户信息表',
            allPages: true
          },
          columns: [
            {
              field: 'userId',
              title: '员工编号'
              // width: 120
            },
            {
              field: 'userName',
              title: '员工姓名'
              // width: 150
            },
            {
              field: 'userTelno',
              title: '员工联系方式'
              // width: 180
            },
            {
              field: 'userBirthdate',
              title: '证件编号'
              // width: 280
            },
            {
              field: 'userTechnicalgrade',
              title: '职称/级别'
              // width: 180
            },
            {
              field: 'userArea',
              title: '员工所属Base地'
              // width: 420
            }
          ]
        },
        tableGridDataSourceOption: {
          ref: 'userDataSource',
          type: 'json',
          pageSize: 10,
          transportReadUrl: '/service/sysMng/user/findUserAccPage',
          serverPaging: true,
          dict: [],
          params: {},
          schema: {
            model: {
              id: 'id',
              fields: {
                userId: { editable: false, type: 'string' },
                userName: { editable: false, type: 'string' },
                userTelNo: { editable: false, type: 'string' },
                userSpecialty: { editable: false, type: 'string' },
                userTechnicalgrade: { editable: false, type: 'string' },
                userArea: { editable: false, type: 'string' }
              }
            },
            data: function(response) {
              return response.data.list
            },
            total: function(response) {
              return response.data.total
            }
          }
        },
        selectData: []
      }
    },
    mounted() {

    },
    methods: {
      /* grid*/
      selectDataItems(res) {
        this.selectData = res
      },
      search(paramVal, validator) {
        this.tableGridDataSourceOption.params = Object.assign(this.tableGridDataSourceOption.params, this.deepCopy(paramVal))
        this.tableGridDataSourceOption.params.pageNum = 1
        this.$refs['UserGrid'].transportReadGrid()
      },
      reset(paramVal) {
        Object.keys(paramVal).forEach(key => {
          if (Array.isArray(paramVal[key])) {
            this.kendoParamsValue[key] = []
          } else {
            this.kendoParamsValue[key] = ''
          }
        })
        this.$refs['UserGrid'].transportReadGrid()
      }
    }
  }
</script>

<style>

</style>
